Skip to content

feat: add Go package#17

Open
acedatacloud-dev wants to merge 1 commit intomainfrom
feat/go-sdk
Open

feat: add Go package#17
acedatacloud-dev wants to merge 1 commit intomainfrom
feat/go-sdk

Conversation

@acedatacloud-dev
Copy link
Copy Markdown
Member

Summary

Go implementation of @acedatacloud/x402-client / acedatacloud-x402 at go/.

What's in it

  • EVMSigner + SignEVMPayment — EIP-3009 TransferWithAuthorization signing for Base / SKALE via go-ethereum's apitypes.TypedData. Signature V is normalized to 27 / 28 to match the canonical Ethereum form expected by the facilitator's ecrecover.
  • SolanaSigner + SignSolanaPayment — SPL TransferChecked with optional ComputeBudget instructions; builds the instruction, signs with a local keypair, submits via JSON-RPC, and returns the on-chain signature in the X-Payment envelope.
  • Handler — unified NewHandler(HandlerOptions{...}) factory with Sign(ctx, accepts) (string, error) and Headers(ctx, accepts) (map[string]string, error). Validates inputs and selects the matching requirement by network.
  • PaymentRequirementFromMap — adapts a raw 402 accepts entry (map[string]any) into the typed struct, so users can bridge it to any HTTP-client shape.

Module

github.com/AceDataCloud/X402Client/go, Go 1.21+, tag-based releases.

Depends on:

  • github.com/ethereum/go-ethereum (EIP-712 + ECDSA)
  • github.com/gagliardetto/solana-go (pubkey / transaction types)
  • github.com/mr-tron/base58 (base58 enc/dec)

Testing

cd go
go vet ./...
go test ./... -race -count=1
  • EIP-712 round-trip: signs a real TransferWithAuthorization with a known Hardhat key, re-derives the digest, and verifies ecrecover returns the signer's address.
  • Default EIP-712 domain: confirms USD Coin / v2 / chainId=8453 match the TypeScript and Python reference.
  • Handler validation: missing signer, unsupported/empty network.
  • Solana: invalid-length key rejection, ATA derivation determinism, TransferChecked data layout, ComputeBudget discriminators.
  • Requirement selection: picks the matching network from accepts, errors clearly when none match.

Live E2E

scripts/e2e exercises the full 402 → sign → retry flow against api.acedata.cloud using SKALE_BASE_PRIVATE_KEY:

cd go
SKALE_BASE_PRIVATE_KEY=0x... go run ./scripts/e2e

Integration with the AceDataCloud Go SDK

The Go SDK PR exposes a PaymentHandler interface. The README shows the trivial 4-line bridge so users can drop an x402.Handler into acedatacloud.NewClient.

CI

New .github/workflows/go.yml runs Go 1.21 / 1.22 / 1.23 matrix with race detector.

Go implementation of the x402 payment client, mirroring the TypeScript
and Python packages.

- EVMSigner + SignEVMPayment — EIP-3009 TransferWithAuthorization
  signing for Base/SKALE (uses go-ethereum's apitypes.TypedData +
  crypto.Sign with canonical V=27/28)
- SolanaSigner + SignSolanaPayment — SPL TransferChecked with optional
  ComputeBudget instructions; signs, submits via JSON-RPC, and returns
  the on-chain signature in the X-Payment envelope
- Handler — unified NewHandler(HandlerOptions{Network, EVMSigner,
  SolanaSigner, RPCURL, HTTPClient}) factory with Sign / Headers
  methods and network-based requirement selection
- PaymentRequirementFromMap — helper that adapts a raw 402 'accepts'
  entry (map[string]any) into the typed struct
- Module: github.com/AceDataCloud/X402Client/go, Go 1.21+

Tests verify:
- EIP-712 signature recovery round-trip (signer address recoverable
  from the canonical digest)
- Default USD Coin / v2 / chainId=8453 EIP-712 domain matches the
  TypeScript and Python reference implementations
- Handler validation (missing signer, unsupported network)
- Solana ATA derivation determinism, TransferChecked data encoding,
  ComputeBudget instruction shapes
- Requirement selection logic

Also ships a scripts/e2e binary that hits a real AceDataCloud endpoint
end-to-end using SKALE_BASE_PRIVATE_KEY.

CI: new go.yml workflow tests on Go 1.21 / 1.22 / 1.23 with race detector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant